import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:url_launcher/url_launcher.dart';
// import 'package:untitledceshi/tabs/index.dart';
// import 'package:untitledceshi/tabs/exchange.dart';
// import 'package:untitledceshi/tabs/market.dart';

import '../common.dart';
import 'exchange.dart';
import 'index.dart';
import 'market.dart';

class tabsPage extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<tabsPage> {
  @override
  void initState() {
    super.initState();
    //  eventBus.on<UserLoginEvent>().listen((event) {
    //     print(55555);
    //     print(event.username);
    // });

    //  eventBus.on<UserLoginEvents>().listen((event) {
    //     print(666666);
    //     print(event.username);
    // });
  }

  int _currentIndex = 0;
  final List<Widget> _pages = [Page1(), Page2(), Page3(), Page4()];

  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(
      const SystemUiOverlayStyle(
        statusBarColor: Colors.transparent, // 设置状态栏背景为白色
        statusBarIconBrightness: Brightness.dark, // 状态栏图标为深色（适合浅色背景）
      ),
    );
    return Scaffold(
      body: _pages[_currentIndex],

      bottomNavigationBar: Theme(
        data: Theme.of(context).copyWith(
          splashColor: Colors.transparent,
          highlightColor: Colors.transparent,
        ),
        child: BottomNavigationBar(
          fixedColor: Color(0xff6828FF), //选中的颜色
          unselectedItemColor: Color(0xff0F172B),
          backgroundColor: Color(0xffffffff),
          type: BottomNavigationBarType.fixed,
          currentIndex: _currentIndex,
          onTap: (index) async {
            if (index == 3) {
              Get.toNamed(
                '/web_webview?url=https://test.cg-online.cn/ZGYH/index.html',
              );
              return;
            }
            // if (index == 2) {
            //   var params = {'token': myget('token') ?? ''};
            //   final uri = Uri.parse(baseUrl).replace(queryParameters: params);
            //   if (await canLaunchUrl(uri)) {
            //     await launchUrl(uri);
            //   } else {
            //     throw '无法打开链接: $uri';
            //   }
            //   return;
            // }

            _currentIndex = index;

            setState(() {});
          },
          items: [
            BottomNavigationBarItem(
              label: '首页',
              icon: wImage(
                url: _currentIndex == 0 ? 'tabs/homes' : 'tabs/home',
                width: 25,
              ),
            ),
            BottomNavigationBarItem(
              icon: wImage(
                url: _currentIndex == 1 ? 'tabs/shichangs' : 'tabs/shichang',
                width: 25,
              ),
              label: '市场',
            ),
            BottomNavigationBarItem(
              icon: wImage(
                url: _currentIndex == 2 ? 'tabs/duihuans' : 'tabs/duihuan',
                width: 25,
              ),
              label: '兑换',
            ),
            BottomNavigationBarItem(
              icon: wImage(
                url: _currentIndex == 3 ? 'tabs/shijies' : 'tabs/shijie',
                width: 25,
              ),
              label: '世界',
            ),
            // BottomNavigationBarItem(icon: Icon(Icons.school), label: '团队'),
          ],
        ),
      ),
    );
  }
}

class Page1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 15, vertical: 15),
      child: Pindex(),
    );
  }
}

class Page2 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(vertical: 15),
      child: Market(),
    );
  }
}

class Page3 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Exchange();
  }
}

class Page4 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(child: Text('Page 3'));
  }
}
